package com.frinder.demo7;

import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
//import akka.transactor.Coordinated;
import scala.concurrent.stm.Ref;
import scala.concurrent.stm.japi.STM;

/**
 * Created by frinder on 2017/7/25.
 */
public class EmployeeActor extends UntypedActor {

    final LoggingAdapter logger = Logging.getLogger(getContext().system(), this);

    private Ref.View<Integer> count = STM.newRef(20);

    @Override
    public void onReceive(Object o) throws Throwable {
//        if (o instanceof Coordinated) {
//            Coordinated coordinated = (Coordinated) o;
//            int downCount = (int) coordinated.getMessage();
//            try {
//                coordinated.atomic(() -> STM.increment(count, downCount));
//            } catch (Exception e) {
//                logger.error(e.getMessage(), e);
//            }
//        } else if ("getCount".equals(o)) {
//            getSender().tell(count.get(), getSelf());
//        } else {
//            unhandled(o);
//        }
    }
}
